// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require jquery.hash
//= require jquery-ui

function console_debug(message) {
  <% if Rails.env.development? %>
  console.debug(message)    
  <% end %>
}

function benchmark(name,func) {
  <% if Rails.env.development? %>
  var startTime = new Date();
  func();
  var endTime = new Date();
  console_debug(name + ' 耗时：' + (endTime - startTime)/1000 + 's');
  <% end %>
}

(function($){  
  // 页面缓存
  $page_cache = new Hash();
  $.fn.extend({
    try_to_hide:function(speed){
      if($(this).is(':visible')) {
        // console_debug('hidded')
        $(this).hide(speed);
      }
    },
    try_to_show:function(speed){
      if($(this).is(':hidden')) {
        // console_debug('show')
        $(this).show(speed);
      }
    },
    try_to_add_class:function(class_name) {
      // console_debug('try_to_add_class' + class_name);
      if( !$(this).is('.' + class_name)) {
        $(this).addClass(class_name);
      }
    },
    try_to_remove_class:function(class_name) {
      // console_debug('try_to_remove_class' + class_name);
      if( $(this).is('.' + class_name)) {
        $(this).removeClass(class_name);
      }
    }
  })  
})(jQuery);

function replace_id(id,str) {
//  console_debug(id)
  return str.replace(/NEW_RECORD/g,id)
}
